<template>
  <div class="home">
    <div class="top-menu">
      <div>帅小黑后台管理系统</div>
      <el-menu mode="horizontal" router menu-trigger="hover" background-color="#fff" style="border:none">
        <el-submenu index="t0">
          <template slot="title">
            <i class="el-icon-edit" ></i>
            <span slot="title">{{_userInfo.userName}}</span>
          </template>
          <el-menu-item index="t0-1" route="me">
            <i class="el-icon-star-off"></i>
            <span slot="title">个人信息</span>
          </el-menu-item>
          <el-menu-item index="t0-0" route="/login">
            <i class="el-icon-star-off" ></i>
            <span slot="title">退出登录</span>
          </el-menu-item>
        </el-submenu>
      </el-menu>
    </div>

    <div class="left-menu" v-if="leftMenu.length">
      <el-menu mode="vertical" :collapse="collapse"  unique-opened default-active="l0" router background-color="#393D49" text-color="#f8f8f8" active-text-color="#fff"  @select="changeMenu" style="border:none">
        <template v-for="(menu,pindex) in leftMenu">
          <el-submenu v-if="menu.list" :index="'l'+pindex" :key="pindex">
            <template slot="title">
              <i :class="'el-icon-'+menu.icon"></i>
              <span slot="title">{{menu.name}}</span>
            </template>
            <el-menu-item v-for="(item,index) in menu.list" :index="'l'+pindex+'-'+index" :route="item.path" :key="index">{{item.name}}</el-menu-item>
          </el-submenu>
          <el-menu-item v-else :index="'l'+pindex" :route="menu.path" :key="pindex">
            <i :class="'el-icon-'+menu.icon"></i>
            <span slot="title">{{menu.name}}</span>
          </el-menu-item>
        </template>
      </el-menu>
    </div>

    <div class="main">
      <div class="tab">
        <el-breadcrumb replace separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '' }">帅小黑后台</el-breadcrumb-item>
          <el-breadcrumb-item v-for="(item,index) in _tab" :key="index" :to="{ path: item.path}">{{item.name}}</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
import { mapState } from 'vuex'
export default {
  name: 'home',
  data() {
    return {
      collapse:false,
      leftMenu:[
        {name:"主页",path:"index",icon:"star-off"},
        {name:"element-ui",path:"",icon:"menu",list:[{name:"基础",path:"base"}]},
        {name:"用户管理",path:"user",icon:"star-on"},
        {name:"商品管理",path:"goodsList",icon:"goods"},
        {name:"设置",path:"setting",icon:"setting"}
      ],
      current:0
    }
  },
  computed:mapState(['_tab','_userInfo']),
  components: { 
  },
  beforeRouteEnter(to, from, next) {
    console.log(to,from)
    next(vm => {
      console.log(vm)
    });
  },
  created() {
    let arr = [{id:"1",name:"1"},{id:"2",name:""}]
    if(!arr.every(ele=>ele.id)){
      console.log("id没有全填")
    }else if(!arr.every(ele => ele.name)){
      console.log("name没有全填")
    }
    //this.$message('消息提示')
    // let _userInfo=this.$com.getStorage('_userInfo');
    // if(_userInfo) {
    //   _userInfo=JSON.parse(_userInfo);
    //   this.$store.commit('_login',_userInfo);
    // }
  },
  methods: {
    changeMenu(index,indexPath) {
      console.log(index);
      console.log(indexPath);    
    },
    tabChange(tab) {
      let index=tab.index;
      this.current=index;
      let path=this.tab[index].name;
      this.$router.push({
        path:path,
        name:name
      });
    }
  }
}
</script>

<style lang="scss" scoped>
.el-menu-item.is-active {
  background-color:#409EFF !important;
}
  .home{
    .top-menu{
      position: fixed;
      top:0;
      height: 60px;
      left: 200px;
      right: 0;
      display: flex;
      justify-content: space-between;
      align-items: center;
      background: #fff;
      padding: 0 60px;
      box-shadow: 5px 5px 5px #eee;
    }
    .left-menu{
      position:fixed;
      top:0;
      left:0;
      width: 200px;
      bottom:0;
      background:#393D49;
      border-right:1px solid #eee;
    }
    .main{
      position:fixed;
      left: 200px;
      top: 60px;
      right: 0;
      bottom: 0;
      padding: 15px 30px 30px;
      overflow-y: auto;
      .tab{
        margin-bottom: 15px;
      }
    }
  }
</style>

